package com.example.demo.myspring;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * 处理bean的对象定义
 * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor
 * 处理bean的实例化
 * @see org.springframework.beans.factory.config.BeanPostProcessor
 * Bean的定义信息
* @see org.springframework.beans.factory.config.BeanDefinition
 * lifecycle
 * @see org.springframework.beans.factory.BeanFactory
 * aop
 * @see org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator
 *
 * 重要入口 & 流程：
 * @see org.springframework.context.support.AbstractApplicationContext#refresh()
 * @see org.springframework.beans.factory.support.DefaultListableBeanFactory
 * @see org.springframework.beans.factory.support.DefaultListableBeanFactory#preInstantiateSingletons()
 * @see org.springframework.beans.factory.support.AbstractBeanFactory#doGetBean(java.lang.String, java.lang.Class, java.lang.Object[], boolean)
 *
 */


@Component
@Slf4j
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        log.info("#####{} create {}" ,beanName,bean.toString());
        return bean;
    }
}
